import numpy as np 
import numpy.random as nr
import scipy
import scipy.misc
import cv2.cv as cv # openCV

class snake_image:
    def __init__(self):
        x = np.linspace(-1,1,100)
        X,Y = np.meshgrid(x,x)
        image = np.zeros(X.shape)
        sigmaX = 0.2
        sigmaY = 0.2
        muX = -0.4
        muY = -0.4
        sobelimg = np.zeros(X.shape)
        edgeimg = np.zeros(X.shape)
        #blurred circle
        image = 3*np.exp(-(((X-muX)**2)/(2*sigmaX**2))-(((Y-muY)**2)/(2*sigmaY**2)))
#        
#        ###second_circle 
        sigmaX2 = 0.2
        sigmaY2 = 0.2
        muX2 = 0.4
        muY2 = 0.4
        image2 = 3*np.exp(-(((X-muX2)**2)/(2*sigmaX2**2))-(((Y-muY2)**2)/(2*sigmaY2**2)))
        image = image + image2
#        
        #Tree
#        k = 0
#        l = 49
#        r = 51
#        for j in range (1,10,1):
#            for i in range (l, r, 1):
#                image[i,j] = 1
#                l = l-1
#                r = r+1
                
        
        
        # add noise
        image = image + 0.1 + nr.normal(0.0,0.05,size=X.shape)
        # Putting in roof and ceiling
        image[(image<0).nonzero()] = 0
        image[(image>1).nonzero()] = 1
        # Making an RGB image out of the circle
        im_rgb = np.zeros([100,100,3])
        im_rgb[:,:,0] = image[:]
        im_rgb[:,:,2] = 1-image[:]
        # Making the image 8-bit
        self.image = (im_rgb*255).astype(np.uint8)
        scipy.misc.imsave('cirk.png', self.image)
        
        
        #Sobel
        image = cv.fromarray(image)
        sobelimg = cv.fromarray(sobelimg)
        cv.Sobel(image, sobelimg, 2, 2, apertureSize = 3)
        
        scipy.misc.imsave('cirksobel.png', sobelimg)
#        
        

S = snake_image()
